package com.lwx.design.chain.optimization;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class DefaultFilterChain implements FilterChain {
	private Iterator<Filter> iterator;
	private List<Filter> filters = new ArrayList<Filter>();
	
	public DefaultFilterChain(){
		initFilterChain();
	}
	
	public void initFilterChain(){
		filters.add(new Filter2());
		filters.add(new Filter3());
		filters.add(new Filter1());
		
		iterator = filters.iterator();
	}
	
	@Override
	public void doFilter() {
		if(iterator.hasNext()){
			iterator.next().doFilter(this);
		}
	}
}
